package com.linxianqin.springbootVue.service.impl;

import com.linxianqin.springbootVue.service.CacheService;
import com.linxianqin.springbootVue.utils.CacheUtils;
import com.linxianqin.springbootVue.utils.text.StringUtils;
import net.sf.ehcache.Element;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能描述：
 *
 * @author lxq
 * @version 1.00
 * @Date 2020/12/12
 */
@Service
public class CacheServiceImpl implements CacheService {
    @Override
    public void put(String key, Object value) {
        CacheUtils.put(key,value);
    }

    @Override
    public void put(String cacheName,String key, Object value) {
        CacheUtils.put(cacheName,key,value);
    }

    @Override
    public Object get(String key) {
        Object o = CacheUtils.get( key);
        if (StringUtils.isNull(o))return null;
        Element element = (Element)o;
        return element.getObjectValue();
    }

    @Override
    public Object get(String cacheName, String key) {
        Object o = CacheUtils.get(cacheName, key);
        if (StringUtils.isNull(o))return null;
        Element element = (Element)o;
        return element.getObjectValue();
    }

    @Override
    public void remove(String key) {
        CacheUtils.remove(key);
    }

    @Override
    public void remove(String cacheName, String key) {
        CacheUtils.remove(cacheName,key);
    }

    @Override
    public void removeKeysByCacheName(String cacheName) {
        CacheUtils.removeAll(cacheName);
    }

    @Override
    public List<String> keys(String cacheName) {
        return CacheUtils.keys(cacheName);
    }
}
